package com.chen.permission.controller;

import com.chen.permission.domain.Menu;
import com.chen.permission.service.IMenuService;
import com.chen.basic.utils.AjaxResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/menu")
@Api("菜单管理")
public class MenuController {

    @Autowired
    private IMenuService menuService;

    @GetMapping("/tree")
    public AjaxResult tree(Long userId) {
        try {
            List<Menu> menus = menuService.tree(userId);
            return AjaxResult.me().setData(menus);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("操作错误："+e.getMessage());
        }
    }
}
